package sctu.edu.java.year2016.team01.xuhanmei.day20160607.chapter15_3;

import javax.swing.*;
import java.awt.*;

/**
 * Created by Administrator on 2016/6/7.
 * 试开发一个窗体，在窗体中设计一个进度条，使进度条每次递增滚动
 */
public class FrameandProgress extends JFrame {


    final JProgressBar progressBar = new JProgressBar();

    public FrameandProgress() {//构造方法
//        JFrame jl = new JFrame("15章作业");
//        jl.setSize(200, 300);
//        jl.setVisible(true);
//        jl.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        getContentPane().add(progressBar, BorderLayout.NORTH);
        progressBar.setStringPainted(true);


        Thread t1 = new Thread(new Runnable() {

            int count = 0;

            @Override
            public void run() {
                while (true) {

                    progressBar.setValue(++count);
                    System.out.println("进度条当前值为：" + count);
                    try {
                        wait(100);//相当于sleep(100);
                        notify();
                      //  Thread.sleep(100);
                       // Thread.interrupted();

                    } catch (InterruptedException e) {
                        e.printStackTrace();

                    }



                    if (count == 100) {
                        break;
                    }
                }
            }

        });
        t1.start();
    }



    public static void main(String[] args) {
        init(new FrameandProgress(),200,300);

    }
    public static void init(JFrame frame,int width,int height)
    {
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("15章作业");
        frame.setVisible(true);
        frame.setSize(width,height);
    }
}
